//
// Created by 10377 on 2023/12/2.
//

#include "utils.h"
using std::cout;
using std::endl;

/**
 * 打印输出 vector<int>
 * @param v
 */
void Utils::print(vector<int> v){
    for(int i : v){
        cout << i << " ";
    }
    cout << endl;
}

/**
 * 带描述语句的打印输出 vector<int>
 * @param v
 */
void Utils::print(string des, vector<int> v){
    cout << des ;
    for(int i : v){
        cout << i << " ";
    }
    cout << endl;
}

void Utils::print(string des, vector <vector<int>> v) {
    cout << des << endl;
    for(vector<int> i : v){
        for(int j : i)
            cout << j << " ";
        cout << endl;
    }
}


void Utils::print(string des, vector <string> v) {
    cout << des << endl;
    for(string i : v){
            cout << i << endl;;
    }
}


/**
 * 最长字串长度
 * @param s
 * @return
 */
string lengthOfLongestSubstring(string s){
    string res = "";
    string temp = "";
    for(int st = 0; st < s.size(); ){
        for(int en = st; en < s.size(); ++en){
            int index = temp.find(s[en]);
            if(index == -1){
                temp += s[en];
            }
            else{
                if(temp.size() > res.size())
                    res =  temp;
                temp = "";
                st = index + 1;
                break;
            }
        }
    }
    if(!temp.empty() && res.empty())
        res = temp;
    return res;
}
